/*
* ////////////////////////////////////////////////
*
* 开发者：AZPEP
* 友情链接：
*	-	B站：		零分的考卷			https://space.bilibili.com/257391258
*	-	Github：	AZPEP-BiliBili		https://github.com/AZPEP-BiliBili
*	-	Gitee：		AZPEP_BiliBili		https://gitee.com/AZPEP_BiliBili
*
* CopyRight AZPEP
*
* -------------------------------------------------
* 文件名称：ThrowError.h
* 描述：抛出程序错误
*/


#pragma once
#pragma execution_character_set("utf-8")

//////////////////////////////////////////////////////////////
//			   编译库时使用的dll标头定义，请勿改动！
//////////////////////////////////////////////////////////////
#ifdef THROWERROR_EXPORTS
#define THROWERROR_API __declspec(dllexport)
#else
#define THROWERROR_API __declspec(dllimport)
#endif

//////////////////////////////////////////////////////////////
//							头文件引用
//////////////////////////////////////////////////////////////
#include <string>
#include <Windows.h>
#include "AST_Errors.h"
#include "LogModule.h"

//////////////////////////////////////////////////////////////
//							常量定义
//////////////////////////////////////////////////////////////
#define AstThrowError_ThrowErrorEx(ErrorCode,ErrorMessage,PrintToLog) AstThrowError_RealThrowErrorW(ErrorCode,*new std::wstring(ErrorMessage),PrintToLog,__FILE__,__LINE__)
#define AstThrowError_ThrowError(ErrorCode,ErrorMessage) AstThrowError_ThrowErrorEx(ErrorCode,ErrorMessage,true)
#define AstThrowError_ThrowError_NonWriteLog(ErrorCode,ErrorMessage) AstThrowError_ThrowErrorEx(ErrorCode,ErrorMessage,false)
#define AstThrowError_EmergencyExit(ExitCode) AstThrowError_RealEmergencyExit(ExitCode,true,__FILE__,__LINE__,true)
#define AstThrowError_EmergencyExitEx(ExitCode,OpenLogFile) AstThrowError_RealEmergencyExit(ExitCode,true,__FILE__,__LINE__,OpenLogFile)
#define AstThrowError_EmergencyExit_NonWriteLog(ExitCode) AstThrowError_RealEmergencyExit(ExitCode,false,__FILE__,__LINE__,false)

//////////////////////////////////////////////////////////////
//							函数定义
//////////////////////////////////////////////////////////////
/// <summary>
/// 抛出错误
/// </summary>
/// <param name="ErrorCode">错误代码</param>
/// <param name="ErrorMessage">错误信息</param>
/// <param name="PrintToLog">是否输出到日志</param>
/// <param name="Handle">日志句柄，若PrintToLog=false应为NULL</param>
/// <param name="CodeFile">源码文件</param>
/// <param name="CodeLine">行号</param>
EXTERN_C THROWERROR_API void AstThrowError_RealThrowErrorW(
	AstErrorCode ErrorCode,
	std::wstring ErrorMessage,

	bool PrintToLog,

	std::string CodeFile,
	unsigned long CodeLine
);

/// <summary>
/// 初始化错误抛出
/// </summary>
/// <param name="Handle">日志句柄</param>
/// <returns>成功返回true，失败返回false</returns>
EXTERN_C THROWERROR_API bool AstThrowError_Init(
	ASTLOG_HANDLE Handle
);

/// <summary>
/// 紧急退出程序
/// </summary>
/// <param name="ExitCode">退出代码</param>
/// <param name="CodeFile">发起源代码文件，程序自动填写，不用管</param>
/// <param name="Line">发起源代码行号，程序自动填写，不用管</param>
/// <param name="OpenLogFile">退出后打开日志文件</param>
EXTERN_C THROWERROR_API void AstThrowError_RealEmergencyExit(
	short ExitCode,
	bool PrintToLog,
	std::string CodeFile,
	unsigned long Line,
	bool OpenLogFile = false
	);